import { h, render, VNode } from 'vue'
import DiaLog from './DiaLog.vue'

export type DiaLogProps = {
    message: string,
    title: string,
    successCallback?: any,
    cancelCallback?: any
}

const renderBox: () => VNode = () => {
    const props: DiaLogProps = {
        message: '',
        title: ''
    } as any
    const container = document.createElement('div')
    const boxVNode = h(DiaLog, props)
    render(boxVNode, container)
    document.body.appendChild(container)
    return boxVNode
}

let boxInstance: any
const DiaLogFun = (props: DiaLogProps): void => {
    console.log(props)
    if (boxInstance) {
        const boxVue = boxInstance.component
        boxVue.proxy.open(props)
    } else {
        boxInstance = renderBox()
        DiaLogFun(props)
    }
}

export default DiaLogFun